//
//  RequestData.m
//  Movie
//
//  Created by lanou3g on 15/7/1.
//  Copyright (c) 2015年 lanou3g. All rights reserved.
//

#import "RequestData.h"

@implementation RequestData

- (void)requestWithUrl:(NSString *)url andDelegate:(id<RequestFinishDelegate>)delegate{
    //1.创建url对象
    NSURL *reqUrl = [NSURL URLWithString:url];
    //2.创建请求对象
    NSURLRequest *request = [NSURLRequest requestWithURL:reqUrl];
    //3.发送异步请求
    [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
        //设置代理
        self.delegate = delegate;
        //4.传值
        if(data){
            [_delegate requestSuccess:data];
        }
        if(connectionError){
            [_delegate requestError:connectionError];
        }
    }];
}

@end
